package yingke.com.yingke.ui.right;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avos.avoscloud.AVUser;

import yingke.com.yingke.R;
import yingke.com.yingke.ui.SettingActivity;

import static yingke.com.yingke.R.id.right_close_iv;

/**
 * A simple {@link Fragment} subclass.
 */
public class RightFragment extends Fragment implements View.OnClickListener {


    private LinearLayout ll_close;
    private TextView right_name;
    private TextView right_id;
    private TextView right_signature;

    public RightFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_right, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();
    }

    private void initData() {
        right_id.setText(AVUser.getCurrentUser().getUsername());
        right_name.setText((CharSequence) AVUser.getCurrentUser().get("nickname"));
        right_signature.setText((CharSequence) AVUser.getCurrentUser().get("signature"));
    }

    private void initView(View view) {
        view.findViewById(right_close_iv).setOnClickListener(this);
        ll_close = (LinearLayout) view.findViewById(R.id.right_hint_ll);
        view.findViewById(R.id.right_user_iv).setOnClickListener(this);
        view.findViewById(R.id.right_search).setOnClickListener(this);
        view.findViewById(R.id.right_setting).setOnClickListener(this);
        right_name = (TextView) view.findViewById(R.id.right_user_name_tx);
        right_id = (TextView) view.findViewById(R.id.right_user_id_tx);
        right_signature = (TextView) view.findViewById(R.id.right_user_signature_tx);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.right_close_iv://手机验证
                ll_close.setVisibility(View.GONE);
                break;
            case R.id.right_user_iv://点击头像进入个人信息
                getActivity().startActivity(new Intent(getContext(), InformationActivity.class));
                break;
            case R.id.right_search://左上角查询图标
                getActivity().startActivity(new Intent(getContext(),SearchActivity.class));
                break;
            case R.id.right_setting://跳转设置界面
                getActivity().startActivity(new Intent(getContext(), SettingActivity.class));
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }
}
